Add session-aware prefix caching and /v1/stats endpoint - #199
Merged
Conversation
stikves
commented
Aug 26, 2026
Contributor
- X-Session-ID header enables KV cache reuse across requests in the same conversation (engine's TokenHistory detects prefix overlap)
- GET /v1/stats returns JSON metrics: throughput, prefix hit rate, memory
- Remove unconditional engine.reset() from chat path — let the engine handle prefix detection internally for 10-20x TTFT improvement on multi-turn conversations
- Completions endpoint retains reset (lm-eval sends unrelated prompts)
- X-Session-ID header enables KV cache reuse across requests in the same conversation (engine's TokenHistory detects prefix overlap) - GET /v1/stats returns JSON metrics: throughput, prefix hit rate, memory - Remove unconditional engine.reset() from chat path — let the engine handle prefix detection internally for 10-20x TTFT improvement on multi-turn conversations - Completions endpoint retains reset (lm-eval sends unrelated prompts)
Single-client usage (no header) now gets prefix caching automatically. Multi-client callers can still differentiate sessions via the header.
Contributor
Author
|
Tested locally Unit tests are also passing to verify isolated components. |
stikves
marked this pull request as ready for review
August 27, 2026 01:12
stikves
requested review from
alejandro-isaza,
carinapeng,
gokulkrishna98,
guru-desh,
kevchengcodes,
parispittman and
tjia1818
August 27, 2026 05:11
Compute promptTokens.map { Int32($0) } once per handler and reuse for
both prepareForRequest and recordPromptTokens. Eliminates one unnecessary
heap allocation per request (up to 512KB at 128K context).
Lewis300
approved these changes
Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.